# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>

pkgbase=geocode-glib
pkgname=(geocode-glib-common geocode-glib geocode-glib-2)
pkgver=3.26.4
pkgrel=3
pkgdesc="Helper library for geocoding services"
url="https://gitlab.gnome.org/GNOME/geocode-glib"
arch=(x86_64)
license=(LGPL)
makedepends=(gobject-introspection git gtk-doc meson glib2 json-glib libsoup
             libsoup3)
_commit=210abe69d68e38947106f4680631c369b0c23189  # tags/3.26.4^0
source=("git+https://gitlab.gnome.org/GNOME/geocode-glib.git#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd geocode-glib
  git describe --tags | sed 's/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd geocode-glib
}

build() {
  local meson_options=(
    -D enable-installed-tests=false
  )

  arch-meson geocode-glib build2 "${meson_options[@]}" -D soup2=true
  arch-meson geocode-glib build3 "${meson_options[@]}" -D soup2=false
  meson compile -C build2
  meson compile -C build3
}

check() {
  # Tests need locales we don't have: en_GB.UTF-8 fr_FR.UTF-8 cs_CZ.UTF-8
  meson test -C build2 --print-errorlogs || :
  meson test -C build3 --print-errorlogs || :
}

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

package_geocode-glib-common() {
  pkgdesc+=" (common files)"
  depends=(glib2 json-glib)

  meson install -C build2 --destdir "$pkgdir"
  meson install -C build3 --destdir "$pkgdir"

  cd "$pkgdir"

  _pick soup2 usr/include/geocode-glib-1.0
  _pick soup2 usr/lib/libgeocode-glib.so*
  _pick soup2 usr/lib/pkgconfig/geocode-glib-1.0.pc
  _pick soup2 usr/lib/girepository-1.0/GeocodeGlib-1.0.typelib
  _pick soup2 usr/share/gir-1.0/GeocodeGlib-1.0.gir
  _pick soup2 usr/share/gtk-doc/html/geocode-glib

  _pick soup3 usr/include/geocode-glib-2.0
  _pick soup3 usr/lib/libgeocode-glib-2.so*
  _pick soup3 usr/lib/pkgconfig/geocode-glib-2.0.pc
  _pick soup3 usr/lib/girepository-1.0/GeocodeGlib-2.0.typelib
  _pick soup3 usr/share/gir-1.0/GeocodeGlib-2.0.gir
  _pick soup3 usr/share/gtk-doc/html/geocode-glib-2
}

package_geocode-glib() {
  pkgdesc+=" (Legacy)"
  depends=(geocode-glib-common="$pkgver-$pkgrel" libsoup-2.4.so)
  provides=(libgeocode-glib.so)

  mv soup2/* "$pkgdir"
}

package_geocode-glib-2() {
  depends=(geocode-glib-common="$pkgver-$pkgrel" libsoup-3.0.so)
  provides=(libgeocode-glib-2.so)

  mv soup3/* "$pkgdir"
}

# vim:set sw=2 sts=-1 et:
